class MyPromise{ //
    constructor(fun){
        this.status = 'pending';//进行中
        this.val = '';//成功的数据
        this.error = '';//失败的数据
        let resolve = (data) => {
            if(this.status === 'pending'){
                this.status = 'fulfilled';//已成功
                this.val = data;
            }
        }

        let reject = (error) => {
            console.log("======")
            if(this.status === 'pending'){
                this.status = 'rejected'; //已失败
            }
        }

        fun(resolve,reject)
    }

    then(onFulfilled,onRejected){
        //成功的方法  失败的方法
        if(this.status === 'fulfilled'){
            onFulfilled(this.val);
        }else{
            console.log("4567890")
            onRejected(this.error);
        }
    }
}

let p1 = new MyPromise((resolve,reject) => {
    resolve("成功")
        // reject('error');
})

p1.then(res => {
    console.log(res)
},(error) => {
    console.log(error)
})